package com.migu.rbac.util;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.migu.rbac.vo.ErrorCodes;

/**
 * 后台响应对象
 * @param <T>
 */
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class Response<T> {
    private boolean isSuccess;
    private Integer errorCode;
    private String errorMsg;
    private T body;
    private long timeStamp;
    private String redirectUrl;

    public Response() {
    }

    public Response(ErrorCodes error) {
        this.isSuccess = false;
        this.errorCode = error.getCode();
        this.errorMsg = error.getDesc();
        this.setTimeStamp(System.currentTimeMillis());
    }

    public static Response req_ok(Object body) {
        Response r = new Response();
        r.setIsSuccess(true);
        r.setBody(body);
        r.setTimeStamp(System.currentTimeMillis());
        return r;
    }

    public Response(boolean isSuccess) {
        this.isSuccess = isSuccess;
        this.setTimeStamp(System.currentTimeMillis());
    }


    public Response(boolean isSuccess, T body) {
        this.isSuccess = isSuccess;
        this.body = body;
        this.setTimeStamp(System.currentTimeMillis());
    }

    public Response(boolean isSuccess, String errorMsg) {
        this.isSuccess = isSuccess;
        this.errorMsg = errorMsg;
        this.setTimeStamp(System.currentTimeMillis());
    }

    public Response(boolean isSuccess, Integer errorCode, String errorMsg) {
        this.isSuccess = isSuccess;
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
        this.setTimeStamp(System.currentTimeMillis());
    }

    public boolean getIsSuccess() {
        return isSuccess;
    }

    public void setIsSuccess(boolean success) {
        isSuccess = success;
    }

    public Integer getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(Integer errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public T getBody() {
        return body;
    }

    public void setBody(T body) {
        this.body = body;
    }

    public long getTimeStamp() {
        return timeStamp;
    }

    public void setTimeStamp(long timeStamp) {
        this.timeStamp = timeStamp;
    }

    public String getRedirectUrl() {
        return redirectUrl;
    }

    public void setRedirectUrl(String redirectUrl) {
        this.redirectUrl = redirectUrl;
    }

    @Override
    public String toString() {
        return "Response{" +
                "isSuccess=" + isSuccess +
                ", errorCode=" + errorCode +
                ", errorMsg='" + errorMsg + '\'' +
                ", body=" + body +
                ", timeStamp=" + timeStamp +
                ", redirectUrl='" + redirectUrl + '\'' +
                '}';
    }
}
